package com.yc.ioc.bean5_conditional;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @author zwei
 * @create 2024-07-29 9:52
 */
public class SystemConditional implements Condition {
    private Logger logger=Logger.getLogger(SystemConditional.class);
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Environment env=context.getEnvironment();
        String username=env.getProperty("user.home");
        String userid=env.getProperty("user.dir");
        String osname=env.getProperty("os.name");
        String javapath=env.getProperty("java.home");
        logger.info(username+"\t"+userid+"\t"+osname+"\t"+javapath);
        if (osname.contains("Windows")){
            return true;
        }
        return false;
    }
}
